﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using M7;
using System.Linq;
using System.Threading;

namespace C7
{
	/// <summary>
	/// Interaction logic for InternetModule.xaml
	/// </summary>
    public partial class CheckoutModule : UserControl
    {
        private WindowOperations WindowOPs = new WindowOperations();
        public CheckoutModule()
        {
            this.InitializeComponent();
            WindowOPs.TextBoxesToHandlers(LayoutRoot);
            WindowOPs.WindowToAnimationHandlers(LayoutRoot, true);
        }

        private void MenuM_Loaded(object sender, RoutedEventArgs e)
        {
            Order.NotPaid();
        }

        private void imgFavorite_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {

        }

        private void imgThumbUp_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {

        }

        private void imgThumDown_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {

        }

        private void spOK_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Msg SendMsg = new Msg(Properties.Settings.Default.Port, Properties.Settings.Default.TableID);
            SendMsg.enumMethod = enumCustomer.CustomerSignOut;
            var customers = from cust in Info.current.customers
                            where cust.CustomerID.Equals(Info.current.CustomerID)
                            select cust;
            SendMsg.obj = customers.ToList()[0];
            TcpConnection.SendingQueue.Enqueue(SendMsg);

            Info.window.Dispatcher.Invoke(new ThreadStart(() =>
                {
                    var users = from user in Info.UsersPanel.Children.OfType<FrameworkElement>()
                                from cust in Info.current.customers
                                where cust.CustomerID.Equals(Info.current.CustomerID)
                                && user is CurrentUser
                                && (user as CurrentUser).tbUserName.Text.Equals(cust.Username)
                                select user;
                    foreach (var item in users)
                    {
                        Info.UsersPanel.Children.Remove(item);
                        break;
                    }
                    var userr = Info.UsersPanel.Children[Info.UsersPanel.Children.Count - 1];
                    foreach (FrameworkElement i in Info.UsersPanel.Children)
                    {
                        if (i == userr)
                            i.Margin = new Thickness(4, 0, 0, 0);
                        if (i != userr && i != Info.window.imgAdd)
                            i.Margin = new Thickness(4, 0, 0, 24);
                    }

                }));
        }

        private void spClose_MouseDown(object sender, MouseButtonEventArgs e)
        {

        }

        
    }
}